// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "BillboardCloudSettingsCustomization.h"
#include "SimplygonUE4UI.h"

#include "IDetailChildrenBuilder.h"
#include "IDetailPropertyRow.h"
#include "PropertyCustomizationHelpers.h"

TSharedRef<IPropertyTypeCustomization> FBillboardCloudSettingsPropertyCustomization::MakeInstance()
{
	return MakeShareable(new FBillboardCloudSettingsPropertyCustomization());
}

void FBillboardCloudSettingsPropertyCustomization::CustomizeHeader(TSharedRef<IPropertyHandle> StructPropertyHandle, FDetailWidgetRow& /*HeaderRow*/, IPropertyTypeCustomizationUtils& /*StructCustomizationUtils*/)
{
}

void FBillboardCloudSettingsPropertyCustomization::CustomizeChildren(TSharedRef<IPropertyHandle> StructPropertyHandle, IDetailChildrenBuilder& ChildBuilder, IPropertyTypeCustomizationUtils& /*StructCustomizationUtils*/)
{
	// Retrieve structure's child properties
	uint32 NumChildren;
	StructPropertyHandle->GetNumChildren(NumChildren);
	TMap<FName, TSharedPtr<IPropertyHandle>> PropertyHandles;
	for (uint32 ChildIndex = 0; ChildIndex < NumChildren; ++ChildIndex)
	{
		TSharedRef<IPropertyHandle> ChildHandle = StructPropertyHandle->GetChildHandle(ChildIndex).ToSharedRef();
		FProperty* Property = ChildHandle->GetProperty();
		if (Property)
		{
			const FName PropertyName = ChildHandle->GetProperty()->GetFName();
			PropertyHandles.Add(PropertyName, ChildHandle);
		}
	}

	// Hide the BillboardMode property of the FBillboardCloudSettings in the UI since only one of the options,
	// the Outer Shell option, is valid for stand-ins.
	PropertyHandles.FindAndRemoveChecked(GET_MEMBER_NAME_CHECKED(FBillboardCloudSettings, BillboardMode));

	for (auto Iter(PropertyHandles.CreateConstIterator()); Iter; ++Iter)
	{
		/*IDetailPropertyRow& SettingsRow =*/ ChildBuilder.AddProperty(Iter.Value().ToSharedRef());
	}
}

FBillboardCloudSettingsPropertyCustomization::FBillboardCloudSettingsPropertyCustomization()
{
}